<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%String path = request.getContextPath() ;%>

<script type="text/javascript">
	var fileGrid = null;
	
	//加载所有文件列表：标识 序号 
	function loadFilesLiger(flag, index, pkId){
		var param = null;
		var ligerNm = "ligergrid_file"+index;
		var _url = '<%=path%>/ass/assTrailCarM/initFilesList.do';
		if(flag == "tcsq"){//拖车申请
			param = {
				pkId: pkId,//拖车主表ID
				tabNm: "ASS_TRAIL_CAR_M",
				flag: flag
			};
		}else if(flag == "rkd" || flag == "ckd" || flag == "crkzl"){//出入库单-资料
			param = {
				pkId: pkId,//拖车明细表ID
				tabNm: "ASS_TRAIL_CAR_D",
				flag: flag
			};
		}else if(flag == "tccz" || flag == "yccz" || flag == "cztcr"){//处置申请-处置提车人
			param = {
				pkId: pkId,//处置主表ID
				tabNm: "ASS_DEAL_SELL",
				flag: flag
			};
		}else if(flag == "tcsh" || flag == "shtcr"){//赎回申请-赎回提车人
			param = {
				pkId: pkId,//赎回主表ID
				tabNm: "ASS_DEAL_REDEEM",
				flag: flag
			};
		}else if(flag == "zycsq"){//转优车申请
			param = {
				pkId: pkId,//转优车主表ID
				tabNm: "ASS_DEAL_CAR",
				flag: flag
			};
		}else if(flag == "tccfj"){//停车场附件
			param = {
				pkId: pkId,//停车场有效期表ID
				tabNm: "ASS_PARKING_VALID",
				flag: flag
			};
		}else if(flag == "tcclsfj"){//停车场历史附件
			param = {
				pkIdList: pkId,//停车场有效期表idList
				tabNm: "ASS_PARKING_VALID",
				flag: flag
			};
		}else{
			$.ligerDialog.SQalert({content: "文件标识不可识别,文件列表读取失败！" , SQ_type: "warning" });
			return false;
		}
        load_FileList(ligerNm, _url, param, flag, index);
	}
	
	//加载
	function load_FileList(ligerNm, _url, param, flag, index){
		$("#"+ligerNm).ligerGrid({
				usePager: false,
				url: _url,
				method : 'get',
				parms:param,
				columns:getColumns(flag, index),//动态获取列
				pageSize:10,
				root:'rows',
				record:'total',
				hideLoadButton : true,
				width: '100%',
				rownumbers:true,
				checkbox:true,//列表是否有选择框
				onAfterShowData: function () {
					$( ".gridTip").grid_ligerTip();
					SetIframe_height ();
				}
		});
		fileGrid = liger.get(ligerNm);
		fileGrid.options.isSingleCheck = false;//列表是否为单选
	}
	
	//获取列表列
	function getColumns(flag, index){
		var col_data = [
				{ display: '名称', name: 'fileNm', minwidth: 200, enabledSort:true },
				{ display: '提交人员', name: 'crtUsrRlNm', width: 200, enabledSort:true },
				{ display: '提交时间', name: 'crtTm', width: 200, render:renderDate2, enabledSort:true },
				getGridOperColumnContent(index)//操作列
			];
		if(flag == "rkd" || flag == "ckd" || flag == "crkzl"){
			col_data = [
				{ display: '资料名称', name: 'fileRem', minwidth: 200, enabledSort:true },
				{ display: '附件', name: 'fileNm', minwidth: 200, enabledSort:true },
				{ display: '提交时间', name: 'crtTm', width: 200, render:renderDate2, enabledSort:true },
				{ display: '验证状态', name: 'audStsCd', width: 200, enabledSort:true,
					render: function (rowdata, rowindex, value, column) { 
						var h = '未验证';
		                if(rowdata.audStsCd == "1"){
		                	h = '已验证';
		                }else if(rowdata.audStsCd == "2"){
		                	h = '验证未通过';
		                };
						return h;
					}},
				getGridOperColumnContent(index)//操作列
			];
		}else if(flag == "tcclsfj"){
			col_data = [
				{ display: '合同有效期', name: '', width: 300, enabledSort:true,
					render: function (rowdata, rowindex, value, column) {
						var h = '';
						h+=renderDate(rowdata.beginDt);//格式化时间
						h+=' - ';
						h+=renderDate(rowdata.endDt);//格式化时间
						return h;
					}},
				{ display: '上传文件名', name: 'fileNm', minWidth: 100,
					render: function (rowdata, rowindex, value){
						var h;
						h='<a href="javascript:uploadFileByUrl(';
						h+="'"+rowdata.filePath+"'";
						h+=",'"+rowdata.fileNm+"'";
						h+=')">'+rowdata.fileNm+'</a>';
						return h;
					}},
				{ display: '上传者', name: 'crtUsrRlNm', width: 200, enabledSort:true },
				{ display: '上传时间', name: 'crtTm', width: 200, render:renderDate2, enabledSort:true }
			];
		}
		return col_data;
	}
	
	//操作列
	function getGridOperColumnContent(index){
		var delFlag = $("#delFlag").val();
		var data = {
			display: '操作',
			isSort: false,
			minWidth: 100,
			render: function (rowdata, rowindex, value){
				var h="";
				h+='<a class="sq-button-hasicon" href="javascript:uploadFileByUrl(';
                h+="'"+rowdata.filePath+"'";
                h+=",'"+rowdata.fileNm+"'";
                h+=')"><i class="sqBtnIco_8"></i>下载</a>';
                //是否有删除操作：1 是 0 否
				if(null != delFlag && "1" == delFlag){
					h+='<a class="sq-button-hasicon" href="javascript:uploadFileDeleteRow(';
					h+="'"+rowdata.id+"'";
					h+=",'"+index+"'";
					//h+=",'ligergrid_bankacc'";
					h+=')"><i class="sqBtnIco_7"></i>删除</a>';
				}
				//判断是不是追加的-只显示未保存到数据库
				if(null != rowdata.doSthFlag && "1" == rowdata.doSthFlag){//是否只有删除操作：1 是 0 否
					h='<a class="sq-button-hasicon" href="javascript:deleteSelectedRow(';
					h+="'"+rowindex+"','";//行号
					h+=rowdata.ligerIndex+"'"+')"><i class="sqBtnIco_7"></i>删除</a>';
				}
				return h;
			}
		};
		return data;
	}
	
	//下载文件方法
	function uploadFileByUrl(_url,_name){
		if(SQ.regs.img.test(_name)){
			SQ.imgPreview(_url, true);
		}else{
			window.open(_url);
		}
	}
	
	//删除调用方法
	function uploadFileDeleteRow(id, index){
		if(!id){
			$.ligerDialog.SQalert({content: LogUtils.LOG_CMM_SELECT_MORE_ROW , SQ_type: "warning" });
			return;
		}
		$.ligerDialog.confirm('确定删除吗?', function (flag) {
			if(flag == false)return;
			var wait_dialog = null;
			$.ajax({
				type: 'post',
				dataType:'json',
				data:{id:id},
				url: '<%=path%>/system/sysulfilesrec/removeById.do',
				beforeSend: function(){
					wait_dialog=$.ligerDialog.SQalert({content: LogUtils.LOG_CMM_DATA_LOADING ,SQ_type: "waitting" });
				},
				success:function(msg){
					wait_dialog.close();
					if(msg.success == 1){
						$.ligerDialog.SQalert({content:msg.info, SQ_type: "success"});
						liger.get("ligergrid_file"+index).reload();//刷新
					}else{
						$.ligerDialog.SQalert({content:msg.info, SQ_type: "error"});
					}
				}
			});
		});
	}
	
	//调整
	function iframeResize () {
		if (parent.mainApp) {
			parent.mainApp.parentTab.onResize();
		};
	}
	
	//刷新附件列表
	function refreshUlFileRecList(index){
		liger.get("ligergrid_file"+index).reload();
	}
	
	//刷新附件列表:重新设置
	function refreshUlFileRecListByPkId(_pkId,_tabNm,index){
		fileGrid = liger.get("ligergrid_file"+index);
		fileGrid.setParm("pkId",_pkId);
		fileGrid.setParm("tabNm",_tabNm);
		fileGrid.reload();
	}
	
	//删除选中行-不用选中即可删除当前行
	function deleteSelectedRow(index,ligerIndex){
		fileGrid = liger.get("ligergrid_file"+ligerIndex);
		//var index = fileGrid.getSelected().__index;
		//fileGrid.deleteSelectedRow();
		fileGrid.deleteRow(index);
		//根据序号设置不同的参数
		if(ligerIndex == 1){
			upload_result_params1.splice(index, 1);
		}else if(ligerIndex == 2){
			upload_result_params2.splice(index, 1);
		}else{
			upload_result_params.splice(index, 1);
		}
	}
</script>